package com.example.demo.common;

import com.example.demo.entity.UserInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class UserSessionTools {
    /*
        获取当前登录用户的信息
     */
    public static UserInfo getLoginUser(HttpServletRequest request){
        HttpSession session = request.getSession(false);
        if (session == null && session.getAttribute(ApplicationVariable.SESSION_USERINFO_KEY) == null){
            return  null;
        }
        UserInfo userInfo = (UserInfo) session.getAttribute(ApplicationVariable.SESSION_USERINFO_KEY);
        return userInfo;
    }
}
